<include file="Public:header" />
<include file="Public:menu" />

<div  id="main_content_wrap" class="container_12">
  <div class="container_12 boxbody">
  <h2>
    <if condition="$thisname eq  ''">
      添加用户管理员
      <else />
      编辑用户管理员
    </if>
    <a href="{:U('Admin/index')}" style="position: absolute;right: 10%;background-color: #3391B0"class="button fr mr10">返回管理员列表</a>
  </h2>
  <form action="{:U('Admin/done')}" method="post" id="checkAdminForm"  name="myform" enctype="multipart/form-data">
    <p>
      <label>管理账号：</label>
      <if condition="$thisname eq  ''">
        <input value="{$thisname}" name="adminname" class="text small" placeholder="只能输入英文字母和数字" >
        <else />
        <input value="{$thisname}" name="adminname" readonly class="text small" placeholder="只能输入英文字母和数字">
      </if>
    </p>
    <p>
      <label>手机号：</label>
      <input type="number" value="{$thisphone}" name="phone" placeholder="请输入11位手机号码" class="text small" />
    </p>
    <if condition="$userphone neq null">
      <p>
      <label>已绑定用户：</label>
      <div style="margin-left: 122px;width: 300px;min-height: 20px; margin-top: -52px">
        <foreach name="userphone" item="item">
          <if condition="$item.phone neq  '00001'">
          <input type="number" style="float: left" value="{$item.phone}" readonly class="text1 small" />
          <div style="line-height: 32px;padding: 7px"><a href="{:U('Admin/delete_user',array('id'=>$item['id'],'uid'=>$uid))}"onclick="return delete_user()">删除</a></div>
          </if>
        </foreach>
      </div>
      </p>
    </if>
        <label>添加绑定：</label>
      <div style="margin-left: 122px;width: 300px;min-height: 20px">
        <input type="number" id="phone" style="float: left" value="" name="userphone" placeholder="请输入用户手机号" class="text1 small" />
        <div style="line-height: 32px;padding: 7px"><a onclick="showuser()">查询</a></div>
      </div>

      <select id="checkphone" style="width: 200px;margin-left: 122px;display: none"  onclick="chosethis()">
        <option></option>
      </select>
    <p>
      <label>密&nbsp;&nbsp;&nbsp;码：</label>
      <input type="password" value="" name="password" class="text small" placeholder="请输入密码" >
    </p>
    <p>
      <label>确认密码：</label>
      <input type="password" value="" name="password1" class="text small" placeholder="再次输入密码">
    </p>

    <p class='tac'>
      <input type="hidden" name="super" value="1" />
      <input type="hidden" name="uid" value="{$uid}" />
      <if condition="$thisname eq  ''">
        <input type="button" class="submit" value="保存" onclick="checkthis_add()" />
        <else />
        <input type="button" class="submit" value="保存" onclick="checkthis_edit()" />
      </if>
    </p>
    </form>
    </div>
</div>
<script>
  function delete_user(){

      var mymessage=confirm("确定要解绑该用户吗？");
      if(mymessage==true)
      {
        return true;
      }
      else if(mymessage==false)
      {
        return false;
      }

  }

  function showuser(){
    var phone = document.getElementById("phone").value;
    var select = document.getElementById("checkphone");
    select.style.display="block";
    $.ajax({
      type:"GET",
      url:"__URL__/Check",
      data:{phone:phone},
      dataType: "json",
      success:function(data){
        var obj = document.getElementById("checkphone"); // 获取select对象
        obj.options.length = 0; // 删除原有选项
        for ( var i = 0; i < data.length; i++) {   /*给select赋值*/
          obj.options.add(new Option(data[i],data[i]))
        }
      }
    });
  }

  function chosethis(){
    var sel=document.getElementById("checkphone");
    var index = sel.selectedIndex; // 选中的索引
    var checked = sel.options[index].value;//选中的值
    document.getElementById("phone").value=checked;
  }

  function checkthis_add() {
    var unamereg = /(^\w+$)/ ;
    var adminname = document.myform.adminname.value;
    var phone = document.myform.phone.value;
    var password = document.myform.password.value;
    var password1 = document.myform.password1.value;
    if (adminname == '') {
      alert('请填写用户名')
    }
    else if (adminname.length < 6) {
      alert('用户名不能少于6个字符');
    }
    else if(unamereg.test(adminname) === false) {
      alert("用户名含有非法字符");
    }
    else if (phone.length > 0 && phone.length != 11) {
      alert('请填写正确的手机号');
    }
    else if (password == '') {
      alert('密码不能为空');
    }
    else if (password.length >0 && password.length < 6) {
      alert('密码不能少于6位');
    }else if (password != password1) {
      alert('两次输入密码不一致');
    }

    else {
      document.myform.submit();//button按钮实现提交 方法
    }

  }

  function checkthis_edit() {
    var adminname = document.myform.adminname.value;
    var phone = document.myform.phone.value;
    var password = document.myform.password.value;
    var password1 = document.myform.password1.value;
    if (adminname == '') {
      alert('请填写用户名')
    }
    else if (adminname.length < 6) {
      alert('用户名不能少于6个字符');
    }
    else if (phone.length >0 && phone.length != 11) {
      alert('请填写正确的手机号');
    }
    else if (password.length >0 && password.length < 6) {
      alert('密码不能少于6位');
    }else if (password != password1) {
      alert('两次输入密码不一致');
    }

    else {
      document.myform.submit();//button按钮实现提交 方法
    }

  }
</script>
<include file="Public:footer" />